package android_design_mode.chapter03_builder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

public class Test {

    public static void main(String[] args) {

        Builder builder = new MacbookBuilder();
        Director pcDirector = new Director(builder);
        pcDirector.construct("MSI-B460", "SANC-24`-180HZ-SHAP");

        Computer computer = builder.create();

        System.out.println(computer.toString());

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        String sd = sdf.format(new Date());

        System.out.println(sd);
        System.out.println(new Date().getTime());


//        int corePoolSize,
//        int maximumPoolSize,
//        long keepAliveTime,
//        TimeUnit unit,
//        BlockingQueue<Runnable> workQueue,
//        ThreadFactory threadFactory,
//        RejectedExecutionHandler handler

//        LockSupport lockSupport
//
//        StringBuffer a = new StringBuffer();
//        StringBuilder stringBuilder = new StringBuilder();
//
//        ReentrantLock reentrantLock;
//
//        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor();
//
//        ThreadLocal

        AtomicInteger atomicInteger;


        HashMap hashMap = new HashMap();

        for (int i = 0; i < 1000; i++) {
            hashMap.put(Math.random() + "", i);
        }


        hashMap.put("1001", 1001);

        System.out.println(hashMap.size());

        ////
        System.out.println("Main 线程 开始运行!");
        final BBBB b1 = new BBBB();
        Thread t1 = new Thread() {
            @Override
            public void run() {
                System.out.println("t1 开始运行!");
                b1.mB("HAHA");
                System.out.println("t1 结束运行!");
            }
        };
        t1.start();

        final BBBB b2 = new BBBB();
        Thread t2 = new Thread() {
            @Override
            public void run() {
                System.out.println("t2 开始运行!");
                b1.mC("XIXI");
//                b1.mB("XIXI");
//                b2.mC("XIXI");
                System.out.println("t2 结束运行!");
            }
        };
        t2.start();

        System.out.println("Main 线程 结束运行!");
    }

    static class BBBB {

        synchronized public void mB(String value) {
            for (int i = 0; i < 10; i++) {
                System.out.println(value);
                try {
                    Thread.sleep(150);
                } catch (Exception e) {

                }
            }
        }

        synchronized public void mC(String value) {
            for (int i = 0; i < 10; i++) {
                System.out.println(value);
                try {
                    Thread.sleep(150);
                } catch (Exception e) {

                }
            }
        }

    }


}
